package com.bwsoft.action;

import org.apache.log4j.Logger;

import com.bwsoft.domain.User;

public class UserGroupAction extends BaseAction {

	private static final long serialVersionUID = -162063439631270176L;
	private static Logger LOG = Logger.getLogger(UserGroupAction.class);

	/**
	 * 1.0 获得所有列表
	 */
	public String userGroupIndex() {

		userGroupList = userGroupService.findAllUserGroup();

		return "getUserGroupList";
	}

	/**
	 * 2.0 添加角色
	 */
	@SuppressWarnings("unchecked")
	public String addUserGroup() {
		LOG.info("用户：" + ((User) session.get("User")).getName() + "执行【添加用户组】");
		// 保存user
		msg = userGroupService.saveUser(userGroup);

		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());

		return "mapJsonResult";
	}

	/**
	 * 3.0 删除菜单
	 */
	@SuppressWarnings("unchecked")
	public String deleteUserGroup() {

		LOG.info("用户：" + ((User) session.get("User")).getName() + "执行【删除用户组】");
		// 保存user
		msg = userGroupService.deleteUser(userGroup);

		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());

		return "mapJsonResult";
	}

	/**
	 * 初始化要修改的内容
	 */
	@SuppressWarnings("unchecked")
	public String showModify() {
		userGroup = userGroupService.getUserGroupInfo(userGroup);
		responseJson.put("userGroup", userGroup);
		return "mapJsonResult";
	}

	/**
	 * 保存要修改的内容
	 */
	@SuppressWarnings("unchecked")
	public String saveModify() {
		LOG.info("用户：" + ((User) session.get("User")).getName() + "执行【修改用户组】");
		msg = userGroupService.updateUserGroup(userGroup);

		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());

		return "mapJsonResult";

	}

	/**
	 * 初始化zTree
	 * 
	 * @return
	 */
	public String showZtreeList() {
		try {
			responseListJson = userGroupService.getZtreeList(userGroup);
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		return "listJsonResult";
	}

	@SuppressWarnings("unchecked")
	public String saveZtreeList() {
		LOG.info("用户：" + ((User) session.get("User")).getName() + "执行【修改用户组权限树】");
		msg = userGroupService.saveTree(userGroup);

		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());

		return "mapJsonResult";
	}
}
